
<div class="fixed-bar">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <input type="text" name="keyword" lay-verify="required" placeholder="输入关键字，按回车搜索" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn layui-btn-primary hisi-export">导出</button>
            </div> 
        </div>
    </form>
    
</div>

<table id="dataTable"></table>

{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '470px', height: '500px'}" title="修改外包工厂">修改</a>
	<a href="{:url('status?val=0')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
	<a href="/mp/outgo/index/code/{{ d.code }}" target="_blank" class="layui-btn layui-btn-primary layui-btn-xs"><i class="layui-icon layui-icon-link"></i>外发订单</a>
</script>

<script type="text/html" title="排序模板" id="sortTpl">
    <input type="text" class="layui-input hisi-ajax-input input-sort" onkeyup="value=value.replace(/[^\d]/g,'')" value="{{ d.order }}" data-value="{{ d.id }}" data-href="{:url('sort')}?id={{ d.id }}&field=order">
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('add')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '470px', height: '700px'}" title="添加外包工厂">&nbsp;添加</a>
		<a data-href="{:url('status?val=0')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</script>
<script type="text/html" id="factoryIdTpl">
</script>
<script type="text/javascript">
    layui.use(['table','jquery','form', 'formSelects'], function() {
        var table = layui.table,$=layui.jquery,form = layui.form;var formSelects = layui.formSelects;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {type:'checkbox', fixed:'left'}
                ,{field: 'id', title: '编号', sort: true}
                ,{field: 'name', title: '外包工厂名称'}
                ,{field: 'code', title: '访问惟一编码'}
				,{field: 'address', title: '工厂地址'}
				,{field: 'mobile', title: '联系电话'}
                ,{field:'factory_name',title : '工厂',width:140}
                ,{field: 'sort', title: '排序', templet: '#sortTpl'}
                ,{title: '操作', templet: '#buttonTpl', fixed: 'right'}
            ]]
            ,done(res){
                var data=res.data;
                for (var i in data){
                    $('#factory-ids-'+data[i]['id']).val(data[i]['factory_id']);
                }
                layui.form.render();
            }
        });
        
        form.on('select(factoryIds)', function(data){   
            var val=data.value,id=data.elem.id;
            var elem=($('#'+id));
            $.ajax({
               type: "POST",
               url: "{:url('factoryEdit')}",
               data: "id="+elem.attr("data-id")+"&factory_id="+val,
               dataType:"json",
               success: function(res){
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1});
                    } else {
                         layer.msg(res.msg, {icon: 2,anim: 6});
                    }
               }
            });
        });
    });
</script>